﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using MySql.Data.MySqlClient;

/// <summary>
/// RewardDB 的摘要说明
/// </summary>
public class ScheduleDB : CommonDb
{
    public ScheduleDB()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public ScheduleDetail[] GetSchedules()
    {
        MySqlCommand cmd = DataComponent.CreateMySqlProcCmd("GetSchedules", m_conn);

        ArrayList Schedules = new ArrayList();
        
        try
        {
            m_conn.Open();
            MySqlDataReader reader = cmd.ExecuteReader();

            while(reader.Read())
            {
                ScheduleDetail schedule = new ScheduleDetail();
                schedule.Id = (uint)reader["Id"];
                schedule.Phase = (uint)reader["Phase"];
                schedule.Deadline = (uint)reader["Deadline"];
                schedule.Description = (string) reader["Description"];
                Schedules.Add(schedule);
            }
            reader.Close();
            return (ScheduleDetail[])Schedules.ToArray(typeof(ScheduleDetail));
        }
        catch(MySqlException err)
        {
            throw new ApplicationException("Data err:" + err.ToString());
        }
        finally
        {
            m_conn.Close();
        }
    }

    public void UpdateSchedule(ScheduleDetail scheduleInfo)
    {
        MySqlCommand cmd = DataComponent.CreateMySqlProcCmd("UpdateSchedules", m_conn);
        DataComponent.AddCmdParameters(cmd, "?uId", MySqlDbType.Int32, 10, scheduleInfo.Id);
        DataComponent.AddCmdParameters(cmd, "?uPhase", MySqlDbType.Int32, 10, scheduleInfo.Phase);
        DataComponent.AddCmdParameters(cmd, "?uDeadline", MySqlDbType.Int32, 10, scheduleInfo.Deadline);

        DataComponent.ExecNonQueryCmd(cmd, m_conn);
    }
}
